package skiree.host.abetsy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import skiree.host.abetsy.model.ddp.DdpBanGuMi;
import skiree.host.abetsy.model.ddp.DdpComment;
import skiree.host.abetsy.model.ddp.DdpSearchEpisodes;
import skiree.host.abetsy.model.ddp.DdpSearchAnime;
import skiree.host.abetsy.service.CoreService;

import javax.annotation.Resource;

@Controller
@CrossOrigin
@RequestMapping("/abetsy")
public class ServerController {

    @Resource
    private CoreService coreService;

    @GetMapping("/api/v2/search/episodes")
    @ResponseBody
    public DdpSearchEpisodes<Object> searchEpisodes(String anime, String episode) {
        if (episode == null) return coreService.onSearch(anime);
        return coreService.search(anime, episode);
    }

    @GetMapping("/api/v2/search/anime")
    @ResponseBody
    public DdpSearchAnime<Object> searchAnime(String keyword, String type) {
        if (type == null) type = "";
        return coreService.searchAnime(keyword, type);
    }

    @GetMapping("/api/v2/bangumi/{animeId}")
    @ResponseBody
    public DdpBanGuMi<Object> banGuMi(@PathVariable("animeId") String animeId) {
        return coreService.banGuMi(animeId);
    }

    @GetMapping("/api/v2/comment/{episodeId}")
    @ResponseBody
    public DdpComment comment(@PathVariable("episodeId") String episodeId, String chConvert, String withRelated) {
        return coreService.comment(episodeId, chConvert, withRelated);
    }

}
